<template>
    <l-layout v-if="isShow" class="l-tab-page"  v-loading="pageLoading" element-loading-text="数据保存中" >
        <l-layout>
            <l-select-panel
                v-model="value"
                ref="selectPanel"
                valueKey="f_UserId"
                :columns="columns"
                :loadSelectTable="loadSelectTable"

                style="padding:8px;padding-left:0;"
            >
                <template v-slot:f_Gender="scope" >
                    <el-tag v-if="scope.row.f_Gender == 1" size="mini" type="success">男</el-tag>
                    <el-tag v-else size="mini" type="danger">女</el-tag>
                </template>
            </l-select-panel>
        </l-layout>
    </l-layout>
</template>
<script>
const api = window.$api.organization.userRelation
const apiUser = window.$api.organization.user
export default {
    data(){
        return {
            isShow:true,

            value:'',
            showType:1,

            objectType:1,
            objectId:undefined,
            pageLoading:false,

            columns: [
                {label:'姓名',prop:'f_RealName',minWidth:'110'},
                {label:'账号',prop:'f_Account',width:'110'},
                {label:'性别',prop:'f_Gender',width:'56',align:'center'}
            ]
        };
    },
    computed:{
    },
    created () {
    },
    methods:{
        tableLoadData(){
            this.$refs.selectPanel.init()
        },
        async loadSelectTable(postData){
            this.showType = postData.showType
            postData.sidx = 'F_CreateDate DESC'
            if(postData.showType != 1){
                 postData.page = 1
            }

            const res = await apiUser.getPage(postData)
            const data = res.data.data
            return data
        },

        resetForm(){
            this.value = ''
            this.isShow = false
            this.$nextTick(()=>{
                this.isShow = true
            })
            //this.$refs.selectPanel.reset()
        },
        async setForm(objectId,objectType){
            this.objectId = objectId
            this.objectType = objectType
            let selectList = (await api.getList(this.objectId)).data.data
            this.value = String(selectList.map(t=>t.f_UserId))
            this.tableLoadData()
        },
        
        async saveForm(){
            this.pageLoading = true;
            await api.save(this.objectId,this.objectType,{userIds:this.value})
            this.pageLoading = false;
        }
    }
}
</script>